<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="sec"
	uri="http://www.springframework.org/security/tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<%@ include file="/inc.jsp" %>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>闪耀先生-购买会员</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />    
    <!-- style -->
    <link href="${pageContext.request.contextPath }/vip/css/usercenter.css" rel="stylesheet">
  </head>
  <body>
    <div class="block buy">
      <h3><span class="org">￥
      				${vipTypePrice }
      	  </span>
      	  闪耀会时尚特权俱乐部金卡会员
      		<s:if test="fdType == '50' ">
				-闪耀会员
			</s:if>  
      </h3>
      <p>享受${invNum }张邀请函；${goldBt }枚金纽扣；${smTicket }张免费上门量体服务,${csTicket }张衬衫券。</p>

        <div class="invituserinfo">
          <ul>
            <li><input type="text" id="name" placeholder="您的姓名" value="${name }"></li>
            <li><input type="text" id="phone" placeholder="手机号" value="${phone }"></li>
             </ul>
          <div class="btnbox"><button type="button" onclick="javascript:_subPay();" class="btn-org btn-block">微信支付</button></div>
        </div><!--E .invituserinfo-->
    </div><!--E .block-->
  </body>

   <script src="<%=basePath%>js/jquery-1.10.1.min.js"></script>
 <script>
 function _subPay(){
	 var name = document.getElementById("name").value;
	 var phone = document.getElementById("phone").value;
	 if(!name || !phone){
		alert("姓名和手机号必填!"); 
		return;
	 }
	 $.ajax({
			type:'post',
			url:'<%=basePath%>public/vipAction!pay.action',
			dataType : 'json', 
			data : {"openId":'${openId}',"fdType":"${fdType}","name":name,"phone":phone},
			timeout:60000,
			success: function (json_str){
				  var temp = eval(json_str);  
				  WeixinJSBridge.invoke('getBrandWCPayRequest',
								  	   {
								  	   "appId" : temp.appId,     //公众号名称，由商户传入     
							           "timeStamp":temp.timeStamp,         //时间戳，自1970年以来的秒数     
							           "nonceStr" : temp.nonceStr, //随机串     
							           "package" : temp.package,     
							           "signType" : "MD5",         //微信签名方式:     
							           "paySign" : temp.paySign//微信签名 
								  	   },
								  	  function(res){
				                          if(res.err_msg == "get_brand_wcpay_request:ok" ) {
				                          	//交易成功
				                        	  _updateVip(temp.orderId);
				                          }else{
				                          	alert("交易失败!"+res.err_msg);
				                          	location.href = "${pageContext.request.contextPath}/public/vipAction!goVipCenterWx.action";
				                          }
				                          // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
				                          //因此微信团队建议，当收到ok返回时，向商户后台询问是否收到交易成功的通知，若收到通知，前端展示交易成功的界面；若此时未收到通知，商户后台主动调用查询订单接口，查询订单的当前状态，并反馈给前端展示相应的界面。
			                          }); 
			}
		});
 }
 function _updateVip(orderId){
	 $.ajax({
			type:'post',
			url:'<%=basePath%>public/vipAction!updateVip.action',
			dataType : 'json', 
			data : {"openId":'${openId}',"fdType":"${fdType}","orderId":orderId},
			timeout:60000,
			success: function (json_str){
				//alert(json_str);
				
				
			}
		});
	 location.href = "${pageContext.request.contextPath}/public/vipAction!goVipCenterWx.action";
 }
 </script>
</html>